import com.demo.model.Student;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2023-03-12
 * Time: 23:37
 */

public class AppBeans {
    public static void main(String[] args) {
        // 1. 获得 Spring 对象.
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        // BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));

        // 2. 从 Spring 对象中获取 Bean 对象.
        //                         如果没有设置@Bean的name熟悉感的话 默认id就是方法名.
        //                         name属性可以设置多个值.设置name属性之后 就不能使用默认规则了(方法名).
        Student student = context.getBean("getStudentBeans", Student.class);
        // Student student1 = factory.getBean("getStudentBeans", Student.class);
        Student student1 = context.getBean("student", Student.class);

        // 3. 使用 Bean 对象
        System.out.println(student);
        // System.out.println(student1);
        System.out.println(student1);
    }
}
